<?php 
	
//send mail
function sendmail($mailto,$subject,$sender_name,$sender_email,$mailcontent,$cc="",$bcc="")
{

       global $ROOT_DIR,$SMTP_SERVER,$INCLUDED_MAIL,$mailErrorMsg;

       $ROOT_DIR=$_SERVER["DOCUMENT_ROOT"]."/";

		if(!$INCLUDED_MAIL)
	   {

			require($ROOT_DIR."phpmailer/class.phpmailer.php");

			$INCLUDED_MAIL=true;

	   }

		if($mailto=="" && $cc=="" && $bcc=="")
			return false;

		$mail = new PHPMailer();
		$mail->PluginDir = $ROOT_DIR."phpmailer/";
		$mail->Host ="localhost";
		$mail->From = "$sender_email";
		$mail->FromName = "$sender_name";
		$arr=split('[;,]',$mailto);
		if($mailto<>"")
	   {
			for($i=0;$i<count($arr);$i++)
			{
				$mailto=$arr[$i];
				$mail->AddAddress("$mailto");
			}
	    }
		if($bcc<>"")
   	    {
			$arr=split('[;,]',$bcc);
			for($i=0;$i<count($arr);$i++)
			{
				$bcc=$arr[$i];
				$mail->AddBCC("$bcc");

			}
	    }
		if($cc<>"")
   	    {
			$arr=split('[;,]',$cc);
			for($i=0;$i<count($arr);$i++)
			{
				$cc=$arr[$i];
				$mail->AddCC("$cc");
			}
	    }
		$mail->AddReplyTo("$sender_email", "$sender_name");
		$mail->WordWrap = 50;           
		if ($attachment!="")			
			$mail->AddAttachment($attachment);         // add attachments

		$mail->IsHTML(true);                                  // set email format to HTML
		$mail->Subject = $subject;
		$mail->Body    = $mailcontent;
		if(!$mail->Send())
		{
			return false;
		}
		return true;
   }
   
	

   #------------------------------------------------------------------------------------------------
   #Input : dd/mm/yyyy
   #Out   : yyyy-mm-dd
   
   function formatInputDate($str)
   {
		//$str=date("d-m-Y H:i:s");
		
		if($str=="")
			return "0000:00:00 00:00:00";
		list($day,$month,$year,$hour,$minute,$sec) = split('[/.-]|[ ]|:', $str);		
		if($month>1000)
			return $str;
		if($hour!="")
			$str="$year-$month-$day $hour:$minute:$sec";
		else
			$str="$year-$month-$day";
		
		return $str;

   }
   
  
   #Input : yyyy-mm-dd
   #Ouput : dd/mm/yyyy
   function formatOutputDate($str)
   {
		if($str=="")
			return "00:00:0000 00:00:00";
		list($year,$month,$day,$hour,$minute,$sec) = split('[/.-]|[ ]|:', $str);		
		if($month>1000)
			return $str;
		if($hour!="")
			$str="$day/$month/$year $hour:$minute";
		else
			$str="$day/$month/$year";
		
		return $str;

   }
   #Input : yyyy-mm-dd
   #Ouput : l, d F, Y   ex: Wednesday, 11 May, 2011
   function formatOutputDate_Long($str)
   {
		if($str=="")
			return "00:00:0000 00:00:00";
		$inputDate = strtotime($str); 
		$str = date ('l, d F, Y', $inputDate); 
		if($inputDate=="")
			$str ="";
		return $str;
		
   }
   #------------------------------------------------------------------------------------------------
   
// return user ip
function getRealIpAddress() {
	if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	}
	else if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
		$ip = $_SERVER['HTTP_CLIENT_IP'];
	}		
	else {
		$ip = $_SERVER['REMOTE_ADDR'];
	}
	return $ip;
}

#------------------------------------------------------------------------------------------------
function check_file($fileurl)
{
	return is_file(urldecode($fileurl));
}
function format_input_utf8($str)
{
	return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
}
#------------------------------------------------------------------------------------------------
/*
$str = "mary had a Little lamb and she loved it so";
strToUpper -> MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
strToTitle -> Mary Had A Little Lamb And She Loved It So
*/
function StrUpper($str)
{
	return mb_convert_case($str, MB_CASE_UPPER, "UTF-8");
}
function StrTitle($str)
{
	return mb_convert_case($str, MB_CASE_TITLE, "UTF-8");
}

#------------------------------------------------------------------------------------------------
	/**
	 * Replaces url entities with -
	 *
	 * @param string $fragment
	 * @return string
	 */
	function clean_entities($fragment)
	{
		$translite_simbols = array ( 
'#(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)#', 
'#(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)#', 
'#(ì|í|ị|ỉ|ĩ)#', 
'#(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)#', 
'#(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)#', 
'#(ỳ|ý|ỵ|ỷ|ỹ)#', 
'#(đ)#', 
'#(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)#', 
'#(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)#', 
'#(Ì|Í|Ị|Ỉ|Ĩ)#', 
'#(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)#', 
'#(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)#', 
'#(Ỳ|Ý|Ỵ|Ỷ|Ỹ)#', 
'#(Đ)#', 
"/[^a-zA-Z0-9\-\_]/", 
) ; 
$replace = array ( 
'a', 
'e', 
'i', 
'o', 
'u', 
'y', 
'd', 
'A', 
'E', 
'I', 
'O', 
'U', 
'Y', 
'D', 
'-', 
) ; 
$fragment = trim($fragment);
$fragment = preg_replace($translite_simbols, $replace, $fragment); 
$fragment = preg_replace('/(-)+/', '-', $fragment);

		return strtolower($fragment);
	}

#------------------------------------------------------------------------------------------------
?>